package com.geccocrawler.gecco.demo.heilongjiang;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: weixiaohu
 * Date: 2019/6/3
 * Time: 15:05
 */
@PipelineName("haerbingPipeline")
public class ProcessPipeline implements Pipeline<Results> {
    private static List<Item> list = Lists.newCopyOnWriteArrayList();
    private int count = 0;

    @Override
    public void process(Results results) {
        List<Item> datas = results.getList();
        datas.remove(0);
        count++;
        list.addAll(datas);
        if(count == RegionProcessPipeline.regionRequests.size()){
            ExcelWriter writer;
            if("yd".equalsIgnoreCase(results.getType())) {
                writer = ExcelUtil.getWriter("d:/spider/定点药店.xlsx");
            }else{
                writer = ExcelUtil.getWriter("d:/spider/定点医疗机构.xlsx");
            }
            writer.write(list, true);
            writer.close();
        }
    }
}
